#ifndef _H_S_PROMISE_PROCESSOR_H_
#define _H_S_PROMISE_PROCESSOR_H_

#include "../typedefine.h"
#include "SPromise.h"

namespace TB
{
	template<typename T>
	struct SPromiseProcessor
	{
		friend class CPromiseHelper;
	public:
		SPromiseProcessor():
			m_oPromise(true, 1)
		{
		}
	private:
		SPromiseProcessor(bool bIsNull):
			m_oPromise(bIsNull, 1)
		{
		}

	public:
		SPromiseProcessor(const SPromiseProcessor& roProcessor) noexcept : m_oPromise(roProcessor.m_oPromise) {}
		SPromiseProcessor& operator=(const SPromiseProcessor& roProcessor) noexcept { m_oPromise = roProcessor.m_oPromise; return *this; }
		SPromiseProcessor(SPromiseProcessor&& roProcessor) noexcept : m_oPromise(std::move(roProcessor.m_oPromise)) {}
		SPromiseProcessor& operator=(SPromiseProcessor&& roProcessor) noexcept { m_oPromise = std::move(roProcessor.m_oPromise); return *this; }
	public:
		inline const SPromise<T>& GetPromise() const
		{
			return m_oPromise;
		}
		inline SPromise<T>& GetPromise()
		{
			return m_oPromise;
		}
		inline bool Resolve(const T& oData)
		{
			return m_oPromise.m_poInfo->Resolve(oData);
		}
		inline bool Reject(const std::shared_ptr<std::exception>& poError)
		{
			return m_oPromise.m_poInfo->Reject(poError);
		}

	private:
		SPromise<T> m_oPromise;
	};
}

#endif
